/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Classes;

import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author jean
 */
public class ExecutarSQL {

    private String url;
    private String userName;
    private String password;
    private String query;
    private Connection connection = null;
    private Statement statement = null;
    private ResultSet resultSet = null;

    public ExecutarSQL(String driver, String url, String user, String senha, String query) {
        this.url = url;
        this.userName = user;
        this.password = senha;
        this.query = query;
        try {
            Class.forName(driver);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(ExecutarSQL.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void executa() {
        try {
            connection = DriverManager.getConnection(url, userName, password);
            statement = connection.createStatement();
            resultSet = statement.executeQuery(query);
        } catch (SQLException ex) {
            Logger.getLogger(ExecutarSQL.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}